package com.tanhua.server.controller;

import com.tanhua.model.vo.AnswersVo;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.UserReportVo;
import com.tanhua.server.service.TestSoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/*
    灵魂测试
 * @description:
 * @author: Jin L
 * @date: 2021/12/27 10:35
 */
@Slf4j
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {


    @Autowired
    private TestSoulService testSoulService;


    /**
     * 测灵魂-查看结果
     *
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity getMyReport(@PathVariable Long id) {
        UserReportVo userReportVo = testSoulService.getMyReport(id);
        return ResponseEntity.ok(userReportVo);
    }

    /**
     * 灵魂测试提交问卷
     * param
     * @param param
     * @return
     */
    @PostMapping
    public ResponseEntity testSoul(@RequestBody Map<String, List<AnswersVo>> param) {
        String reportId = testSoulService.testSoul(param);
        return ResponseEntity.ok(reportId);
    }

    @GetMapping
    public ResponseEntity questionnaireList() {
        List<QuestionnaireVo> list = testSoulService.questionnaireList();
        return ResponseEntity.ok(list);
    }
}
